package com.hzvtc.bosswang.manageuser.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzvtc.bosswang.managecommon.domain.AjaxResult;
import com.hzvtc.bosswang.manageuser.domain.Grade;
import com.hzvtc.bosswang.manageuser.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/class-manager")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    @PostMapping("/add-grade")
    private AjaxResult addGrade(@RequestBody Grade grade){
        if ( gradeService.addGrade(grade)>0) {
            return new AjaxResult(200, "添加成功", null);
        }
        return new AjaxResult(500,"添加失败",null);
    }

    @PostMapping("/edit-grade")
    private AjaxResult modifyGrade(@RequestBody Grade grade){
        if ( gradeService.editGrade(grade)>0){
            return new AjaxResult(200,"修改成功",null);
        }
        return new AjaxResult(500,"修改失败",null);
    }

    @GetMapping("/view-grade/{id}")
    private AjaxResult selectGradeById(@PathVariable Long id){
        Grade grade = gradeService.selectGradeById(id);
        if (grade!=null){
            return new AjaxResult(200,"查询成功！",grade);
        }
        return new AjaxResult(500,"查询失败",null);
    }

    @PostMapping("/list-grade")
    private AjaxResult listGrade(@RequestBody Grade grade){
        Page<Grade> page=new Page<>();
        page.setSize(10);
        page.setCurrent(1);
        return new AjaxResult(200,"查询成功！", gradeService.listGrade(page,grade));
    }

    @DeleteMapping("/delete-grade/{id}")
    private AjaxResult deleteGrade(@PathVariable Long id){
        if (gradeService.deleteGrade(id)>0){
            return new AjaxResult(200,"删除成功",null);
        }
        return new AjaxResult(500,"删除失败",null);
    }
}
